<script>
import _ from 'lodash'
import moment from 'moment'
export default {
  name: 'Home',
  data () {
    return {}
  },
  created: function () {
    this.duration()
  },
  watch: {
  },
  methods: {
    duration () {
      let start = 1525363200468
      let end = 1532653200468
      console.log('start:' + start)
      console.log('end:' + end)
      let timeMill = end - moment(end).startOf('day').valueOf()
      start = moment(start).startOf('day')
      end = moment(end).startOf('day')
      let years = end.diff(start, 'years', true)
      let months = end.diff(start, 'months', true)
      let weeks = end.diff(start, 'weeks', true)
      let days = end.diff(start, 'days', true)
      let mills = end.diff(start)
      let zero = moment(0).startOf('day')
      let result = 0
      if (_.isInteger(years)) {
        result = zero.add(years, 'years')
      } else if (_.isInteger(months)) {
        result = zero.add(months, 'months')
      } else if (_.isInteger(weeks)) {
        result = zero.add(weeks, 'weeks')
      } else if (_.isInteger(days)) {
        result = zero.add(days, 'days')
      } else {
        result = zero.add(mills, 'milliseconds')
      }
      console.log('result:' + result.valueOf())
      result = result.valueOf() + timeMill
      // 反转
      console.log('result:' + result)
      let duration = moment(result).startOf('day')
      timeMill = result - duration.valueOf()
      zero = moment(0).startOf('day')
      years = duration.diff(zero, 'years', true)
      months = duration.diff(zero, 'months', true)
      weeks = duration.diff(zero, 'weeks', true)
      days = duration.diff(zero, 'days', true)
      mills = duration.diff(zero)
      end = 0
      console.log('end:' + end)
      start = moment(start).startOf('day')
      console.log('start:' + start.valueOf())
      if (_.isInteger(years)) {
        end = start.add(years, 'years')
      } else if (_.isInteger(months)) {
        end = start.add(months, 'months')
      } else if (_.isInteger(weeks)) {
        end = start.add(weeks, 'weeks')
      } else if (_.isInteger(days)) {
        end = start.add(days, 'days')
      } else {
        end = start.add(mills, 'milliseconds')
      }
      end = end + timeMill
      console.log('end:' + end)
    }
  }
}
</script>

<template>
  <el-main>
    导航
  </el-main>
</template>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
